<?php
/**
 * 悠络客摄像头
 */

namespace App\Kuafu\Shop\Service\CameraLibrary;


use App\Kuafu\Shop\Model\CameraModel;
use App\Kuafu\Shop\Service\ShopService;

class CameraFactory
{
    /**
     * Camera model 主设备
     *
     * @var object
     */
    public $cameraInfo;

    public function __construct(?int $cameraId = 0)
    {
//        if ($cameraId === null) {
//            $this->cameraInfo = null;
//            return;
//        }

        $this->cameraInfo = CameraModel::query()->where('id', $cameraId)->first();

        if (empty($this->cameraInfo)) {
            throw new \Exception('非正常请求, 请刷新页面后再试');
        }
    }

    public function getIns()
    {
        switch ($this->cameraInfo->supplier) {
            default:
            case CameraModel::SUPPLIER_YLK:
                // 悠络客
                $class = new YlkCamera($this->cameraInfo);
                break;
            case CameraModel::SUPPLIER_ALIYUN:
                // 阿里云
                $class = new AliYunCamera($this->cameraInfo);
                break;
            case CameraModel::SUPPLIER_YING_LIU:
                // 阿里云
                $class = new YlCamera($this->cameraInfo);
                break;
        }
        return $class;
    }

}
